// const CompressionWebpackPlugin = require("compression-webpack-plugin");
// const TerserPlugin = require("terser-webpack-plugin");
const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  //   productionSourceMap: false,
  //   //配置全局Less
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less",
      patterns: [
        path.resolve(__dirname, "src/style/index.less"),
        // path.resolve(__dirname, "src/styles/mixins.less"),
      ],
    },
  },
  devServer: {
    port: 28848,
  },
  chainWebpack: config => {
    config.resolve.alias
      .set("@", resolve("src"))
  },

  pages: {
    index: {
      //入口
      entry: "src/main.js", // 当使用 title 选项时， // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
      title: "奶盖-个人博客",
    },
  },

  css: {
    extract: true,
    sourceMap: false,
    loaderOptions: {
      less: {
        javascriptEnabled: true,
      },
      postcss: {
        plugins: [
          require("postcss-pxtorem")({
            // 把px单位换算成rem单位
            rootValue: 37.5, //通常结合 lib-flexible 设置 rem 基准值,默认用37.5,不然容易出问题
            // selectorBlackList: [".ignore"], //则是一个对css选择器进行过滤的数组，比如你设置为['fs']，那例如fs-xl类名，里面有关px的样式将不被转换
            propList: ["*"],
          }),
        ],
      },
    },
  },
  //   configureWebpack: (config) => {
  //     if (process.env.NODE_ENV !== "developement") {
  //       config.plugins.push(
  //         new CompressionWebpackPlugin({
  //           algorithm: "gzip",
  //           test: new RegExp("\\.(" + ["js", "css"].join("|") + ")$"),
  //           threshold: 10240,
  //           minRatio: 0.8,
  //         })
  //       );
  //       config.plugins.push(
  //         new TerserPlugin({
  //           terserOptions: {
  //             compress: {
  //               warnings: false,
  //               // drop_console: true,
  //               // drop_debugger: true,
  //               // pure_funcs: ['console.log', 'console.info']
  //             },
  //           },
  //         })
  //       );
  //       config.optimization = {
  //         runtimeChunk: "single",
  //         splitChunks: {
  //           chunks: "all",
  //           cacheGroups: {
  //             libs: {
  //               name: "chunk-libs",
  //               test: /[\\/]node_modules[\\/]/,
  //               priority: 10,
  //               chunks: "initial",
  //             },
  //             viewDesign: {
  //               name: "chunk-element-ui",
  //               priority: 20,
  //               test: /[\\/]node_modules[\\/]_?element(.*)/,
  //             },
  //             moment: {
  //               name: "chunk-moment",
  //               priority: 20,
  //               test: /[\\/]node_modules[\\/]_?moment(.*)/,
  //             },
  //             commons: {
  //               name: "chunk-commons",
  //               test: path.resolve(__dirname, "src/components"),
  //               minChunks: 3,
  //               priority: 5,
  //               reuseExistingChunk: true,
  //             },
  //           },
  //         },
  //       };
  //     }
  //   },
};